package com.juli.school.app.controller.common;

import javax.annotation.Resource;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.alibaba.fastjson.JSONObject;
import com.google.common.base.Strings;
import com.juli.school.service.impl.OauthService;

@Controller
@RequestMapping("oauth")
public class OauthController {
	
	@Resource
	OauthService oauthService;
	
	/**
	 * @Description: 获取认证登陆的url
	 * @author gaoxiang
	 * @date 2017年10月5日 下午4:09:11
	 */
	@RequestMapping("/getOauthUrl")
	String getOauthUrl(String source) {
		if(Strings.isNullOrEmpty(source)) return "";
		return "redirect:"+oauthService.getOauthUrl(source);
	}
	
	@RequestMapping("qq/callback")
	@ResponseBody JSONObject qqCallback(String code) {
		return oauthService.callback("qq",code);
	}
	
	@RequestMapping("weixin/callback")
	@ResponseBody JSONObject weixinCallback(String code) {
		return oauthService.callback("weixin",code);
	}
	
	@RequestMapping("sina/callback")
	@ResponseBody JSONObject sinaCallback(String code) {
		return oauthService.callback("sina",code);
	}
}
